package net.shambolica.ember.jinterface.wrappers.objects.patterns;

import com.ericsson.otp.erlang.OtpErlangObject;
import net.shambolica.ember.jinterface.wrappers.objects.EOMatch;
import net.shambolica.ember.jinterface.wrappers.objects.EOPattern;

import java.util.Map;

/**
 * A pattern representing a term.
 */
public class EOPTerm extends EOPattern {

    private final OtpErlangObject object;

    public EOPTerm(OtpErlangObject object) {
        if (object == null) {
            throw new IllegalArgumentException("null object for pterm");
        }
        this.object = object;
    }

    public OtpErlangObject getObject() {
        return object;
    }

    @Override
    public Map<String, OtpErlangObject> match(OtpErlangObject term, Map<String, OtpErlangObject> acc) {
        return object.equals(term) ? mkAcc(acc) : null;
    }

    @Override
    public OtpErlangObject instantiate() {
        return object;
    }

    @Override
    public boolean isAbstract() {
        return false;
    }
    
}
